package skeleton;

import java.awt.*;
import java.awt.event.*;

import javax.media.opengl.*;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLJPanel;
import javax.swing.*;

public class GLApp_swing extends JFrame {
	
	private GLListener GLL;
	private GLJPanel canvas;
	
	public GLApp_swing() {
		
		super("joglSkeleton2D + swing");
		this.getContentPane().setLayout(new BorderLayout());
		setSize(400, 400);
		setLocationRelativeTo(null);
        this.addWindowListener(new WindowAdapter() { 
            public void windowClosing(WindowEvent we) {
              System.exit(0);
            }
          });

				
		canvas= new GLJPanel();
		GLL= new GLListener();
        canvas.addGLEventListener(GLL);
        this.getContentPane().add(canvas,BorderLayout.CENTER);

        
        JPanel btPane= new JPanel();
        this.getContentPane().add(btPane,BorderLayout.SOUTH);

        JButton button_zi = new JButton("Zoom In");
        button_zi.addActionListener(new bt_zi_Listener());
        btPane.add(button_zi,BorderLayout.WEST);

        JButton button_zo = new JButton("Zoom Out");
        button_zo.addActionListener(new bt_zo_Listener());
        btPane.add(button_zo,BorderLayout.EAST);

	}

	
	public static void main(String[] args)
    {
        GLApp_swing app = new GLApp_swing();
        app.setVisible(true);
    }
	
	
	private class bt_zi_Listener implements ActionListener{
		public void actionPerformed(ActionEvent e){
			canvas.getContext().makeCurrent();
			GLL.zoom(canvas, 0.9);
			canvas.repaint();
		}
	}


	private class bt_zo_Listener implements ActionListener{
		public void actionPerformed(ActionEvent e){
			canvas.getContext().makeCurrent();
			GLL.zoom(canvas, 1.1);
			canvas.repaint();
		}
	}
}
